#!/bin/bash
set -e

# 获取当前脚本目录
ROOT_DIR=$(dirname "$(realpath $0)")
BUILD_DIR="${ROOT_DIR}/build"

# 清理之前的 build 文件夹
if [[ -d "${BUILD_DIR}" ]]; then
  echo "Removing previous build directory: ${BUILD_DIR}"
  rm -rf "${BUILD_DIR}"
fi

# 创建新的 build 文件夹
mkdir -p "${BUILD_DIR}"
cd "${BUILD_DIR}"

# 配置和构建
cmake .. -DCMAKE_BUILD_TYPE=Release
make -j$(nproc)

# 安装到指定目录
make install
echo "Build and installation completed."
